package com.cyzy.controller;

import com.cyzy.dto.Result;
import com.cyzy.pojo.*;
import com.cyzy.service.MiniprogramHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 小程序首页数据控制器
 * @description: 提供小程序首页所需的各种数据接口
 * @author: yangJingShi
 * @date: 2025/1/19
 */
@RestController
@RequestMapping("/miniprogram")
public class MiniprogramHomeController {

    @Autowired
    private MiniprogramHomeService miniprogramHomeService;

    /**
     * 获取轮播图数据
     * @return 轮播图列表
     */
    @GetMapping("/banners")
    public Result getBanners() {
        List<SuBannerAds> bannerList = miniprogramHomeService.getBannerList();
        return Result.ok().message("获取轮播图数据成功").data("bannerList", bannerList);
    }

    /**
     * 获取商品数据
     * @return 商品列表
     */
    @GetMapping("/goods")
    public Result getGoods() {
        List<SuExternalGoods> goodsList = miniprogramHomeService.getGoodsList();
        return Result.ok().message("获取商品数据成功").data("goodsList", goodsList);
    }

    /**
     * 获取快捷入口数据
     * @return 快捷入口列表
     */
    @GetMapping("/quick-entries")
    public Result getQuickEntries() {
        List<SuQuickEntries> quickEntries = miniprogramHomeService.getQuickEntries();
        return Result.ok().message("获取快捷入口数据成功").data("quickEntries", quickEntries);
    }

    /**
     * 获取功能入口数据
     * @return 功能入口列表
     */
    @GetMapping("/entries")
    public Result getFunctionEntries() {
        List<SuFunctionEntries> entriesList = miniprogramHomeService.getFunctionEntries();
        return Result.ok().message("获取功能入口数据成功").data("entriesList", entriesList);
    }

    /**
     * 获取校区公告数据
     * @return 校区公告列表
     */
    @GetMapping("/notices")
    public Result getNotices() {
        List<SuCampusAds> noticeList = miniprogramHomeService.getNoticeList();
        return Result.ok().message("获取校区公告数据成功").data("noticeList", noticeList);
    }

    /**
     * 获取品牌推荐数据
     * @return 品牌推荐列表
     */
    @GetMapping("/recommends")
    public Result getRecommends() {
        List<SuBrandRecommendations> recommendList = miniprogramHomeService.getRecommendList();
        return Result.ok().message("获取品牌推荐数据成功").data("recommendList", recommendList);
    }

    /**
     * 获取首页所有数据（一次性接口）
     * @return 包含所有首页数据的对象
     */
    @GetMapping("/home-data")
    public Result getHomeData() {
        try {
            List<SuBannerAds> bannerList = miniprogramHomeService.getBannerList();
            List<SuExternalGoods> goodsList = miniprogramHomeService.getGoodsList();
            List<SuQuickEntries> quickEntries = miniprogramHomeService.getQuickEntries();
            List<SuFunctionEntries> entriesList = miniprogramHomeService.getFunctionEntries();
            List<SuCampusAds> noticeList = miniprogramHomeService.getNoticeList();
            List<SuBrandRecommendations> recommendList = miniprogramHomeService.getRecommendList();
            
            return Result.ok()
                    .message("获取首页数据成功")
                    .data("bannerList", bannerList)
                    .data("goodsList", goodsList)
                    .data("quickEntries", quickEntries)
                    .data("entriesList", entriesList)
                    .data("noticeList", noticeList)
                    .data("recommendList", recommendList);
        } catch (Exception e) {
            return Result.error().message("获取首页数据失败：" + e.getMessage());
        }
    }
} 